#version 450 core
out vec4 fragment_color;
in vec3 facet_normal;
in vec3 tri_distance;
in vec3 patch_distance;

layout (location = 5) uniform vec3 light_position;
layout (location = 6) uniform vec3 diffuse_material;
layout (location = 7) uniform vec3 ambient_material;

float amplify(float d, float scale, float offset)
{
	d = scale * d + offset;
	d = clamp(d, 0, 1);
	d = 1 - exp2(-2*d*d);
	return d;
}

void main()
{
	vec3 N = normalize(facet_normal);
	vec3 L = light_position;
	float df = max(0.0f, dot(N, L));
	vec3 color = ambient_material + df * diffuse_material;
	float d1 = min(min(tri_distance.x, tri_distance.y), tri_distance.z);
	float d2 = min(min(patch_distance.x, patch_distance.y), patch_distance.z);
	color = amplify(d1, 40, -0.5) * amplify(d2, 60, -0.5) * color;
	fragment_color = vec4(color, 1.0);
}



